<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>站点列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/admin/src/css/layui.css">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>
        .layui-input-inline{margin-top: 5px;}
        .layui-form-label{margin-top: 5px;}
        .layui-btn{margin-top: 5px;}
    </style>
</head>
<body>
<div class="layui-card-body" style="padding: 15px;">
    <table class="layui-hide" id="test" lay-filter="test"></table>

    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="addData">添加</button>
        </div>
    </script>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script src="/admin/src/layui.js" ></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

    <script>
        layui.use(['form','table'], function(){
            var table = layui.table;
            var $ = layui.$;
            var form = layui.form ;
            table.render({
                elem: '#test'
                ,url:'/admin/station/lists'/*,tpa=http://www.ilayuis.com/test/table/demo1.json*/
                ,method:'post'
                ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                ,defaultToolbar: []
                ,title: '站点列表'
                ,cols: [[
                    {field:'id', width:90, title: 'ID', sort: true}
                    ,{field:'uid', width:140, title: '站点名称'}
                    ,{field:'name',  title: '站点联系人'}
                    ,{field:'member',  title: '站点联系方式'}
                    ,{field:'community',  title: '站点所在区域'}
                    ,{field:'spotId',  title: '站点地址'},
                    ,{field:'status', width:80, title: '状态'}
                    ,{field:'createTime', title:'创建时间', width:160}
                    ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:120}
                ]]
                ,page: true
            });
            table.on('tool(test)', function(obj){
                var data = obj.data;
                if(obj.event === 'del'){
                    layer.confirm('确定要删除？', function(index){
                        var postData = {'id':data.id};
                        $.ajax({
                            url : '/admin/station/delete/data',
                            type : 'post',
                            dataType : 'json',
                            data : postData,
                            success : function (backData) {
                                //删除成功
                                if(backData['status'] == 200){
                                    obj.del();
                                    layer.close(index);
                                    layer.msg(backData.message,{time:1200});
                                }else{
                                    layer.msg(backData.message);
                                }
                            }
                        })
                    });
                } else if(obj.event === 'edit'){
                    layer.open({
                        type: 2//0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层)
                        , title: '编辑站点' //不显示标题栏
                        , area : [ '80%', '90%' ]
                        , closeBtn: 1
                        , shade: 0.8//遮幕
                        , id: 'LAY_layuipro' //设定一个id，防止重复弹出
                        // ,btn: [ '表格','取消']
                        , btnAlign: 'c'//按钮排列：居中对齐
                        , moveType: 1 //拖拽模式，0或者1
                        , resize: true
                        , content: '/admin/station/edit2/form?id='+data.id//跳转到想要的界面，这里是我自己项目的跳转界面
                        ,success: function (layero) {
                            var btn = layero.find('.layui-layer-btn');
                            btn.find('.layui-layer-btn0').attr({
                                href: '${path}'
                                , target: '_blank'
                            });
                        }
                    })
                }
            });

        });
    </script>

</body>
</html>